package Z_durable;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import utils.RabbitMQUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author： pang-yun
 * @date： 2021-12-15 10:24
 * 功能目的 ：用于  消息队列 的消费
 */

public class DurableConsumer {
    static final String MESSAGE_DURABLE = "MessageDurable";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMQUtils.getChannel();
        System.out.println("消费持久化消息");

        DeliverCallback callback = (consumerTag, message) -> {
            System.out.println("接收到消息"+new String(message.getBody()));
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };

        channel.basicConsume(MESSAGE_DURABLE,false,callback,message->{
            System.out.println("失败，消息取消");
        });

    }
}
